<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目所属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="enginname" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目属性</label>
                        <div class="layui-input-block">
                            <select name="business" id="business">
                                <option value="">请选择</option>
                                <option value="1">自营</option>
                                <option value="2">联营</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">项目状态</label>
                        <div class="layui-input-block">
                            <select name="state" id="state"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">保函类别</label>
                        <div class="layui-input-block">
                            <div id="hantype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>


<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">项目编号</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="enginnumber" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3">-->
<!--                        <label class="layui-form-label">保证金类型：</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <select id="bondtype" name="bondtype" lay-filter="bondtype">-->
<!--                                <option value="">请选择</option>-->
<!--                            </select>-->
<!--                        </div>-->
<!--                    </div>-->
<!---->
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">保函金额</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="money" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">受益人</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="shouer" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">被担保人</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="beidaner" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">担保人</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="daner" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">开具日期</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" readonly name="kaidt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">有效期</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" readonly name="xiaodt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-col-md3 search_hide none">-->
<!--                        <label class="layui-form-label">手续费</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="shoufee" placeholder="请输入" class="layui-input" autocomplete="off">-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>




    var currButAuth, currTabData,sea_chanid = '',queryStatus=0;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });


        setSouTableExport('投标保函开具');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_bid_bond_kai_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                if(queryStatus === 0){


                    var state = res.data.state;
                    var state_str = '<option value=""></option>';
                    for(var i in state){
                        state_str += '<option value="'+i+'">'+state[i]+'</option>';
                    }
                    $('#state').html(state_str);
                    queryStatus = 1;
                }

                var bondtype_str = '<option value="">请选择</option>';
                var bondtype = res.data.bondtype;
                for (var key in bondtype){
                    if(res.data.is_bondtype == key){
                        bondtype_str += '<option value="'+key+'" selected>'+bondtype[key]+'</option>';
                    }else {
                        bondtype_str += '<option value="'+key+'">'+bondtype[key]+'</option>';
                    }

                }
                $("#bondtype").html(bondtype_str);

                xmselect_dan('hantype', res.data.hantype, res.data.is_hantype, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                });

                xmselect_dan('chanid', res.data.chanid, sea_chanid, function (res) {
                    sea_chanid = res.arr && res.arr.length > 0 ? res.arr[0].value : '';
                    searchTableFunc(form, table);
                });

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,list_bill_cols_str
                ,{field: '', title: '状态',templet:function (e) {
                    if(e.kaidt != '0000-00-00' && e.kaidt != ''){
                        return '已开具';
                    }else{
                        return '未开具';
                    }
                }}
                ,{field: 'enginname', title: '项目名称',event:'enginname',minWidth: 200,templet:function (e) {
                        return '<span class="colorlan">'+e.enginname+'</span>';
                    }}
                ,{field: 'business_name', title: '项目属性'}
                ,{field: 'state_name', title: '项目状态'}
                ,{field: 'bondtype', title: '保证金类型'}
                ,{field: 'hantype', title: '保函类别'}
                ,{field: 'money', title: '保函金额(元)'}
                ,{field: 'created_user', title: '申请人'}
                ,{field: 'created_at', title: '申请时间'}
                ,{field: 'shouer', title: '受益人'}
                ,{field: 'beidaner', title: '被担保人'}
                ,{field: 'daner', title: '担保人'}
                ,{field: 'kaidt', title: '开具日期'}
                ,{field: 'xiaodt', title: '有效期'}
                ,{field: 'shoufee', title: '手续费'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        listTableSearch(form, table);


        table.on('tool(datalist)', function(obj){
            var data = obj.data;
            if(obj.event === 'enginname'){
                openPage('../bid/show.php?id='+data.bidid);
            }
        });
    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('../engin_bond_kai/show.php?id='+trData.id);
    }
    function auth_but_func_add(){
        // openPageEdit('../engin_bond_kai/add.php?close=1&type=bid');
        openPageEdit('../engin_bond_kai/flow_add.php?close=1&type=bid');
    }
    function auth_but_func_add_flow(){
        openPageEdit('../engin_bond_kai/flow_add.php?close=1&type=bid');
    }
    function auth_but_func_edit(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('../engin_bond_kai/edit.php?close=1&id='+trData.id);
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        data_delete(ask_engin_bond_kai_del, {id:trData.id});
    }


</script>
</body>
</html>
